/*===========================================
	Paradigm Engine for Twilight Hack
	Build 1.0
	Texture loading functions
	
	(C)2008 Vicious1988 - Syndicate Development
	Uses PNGU (C)2008 Frontier Dev
===========================================*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <gccore.h>
#include "libpng/pngu/pngu.h"
#include "textures.h"

int totaltex=0;
texobject textures[999];

PNGUPROP imgProp;

int LoadTexture(const char *filename){
	textures[totaltex].texture_data= NULL;
	PNGU_Init ();
	PNGU_SelectFileFromWiiSD (filename);
	PNGU_GetImageProperties (&imgProp);
	textures[totaltex].texture_data = memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4);
	GX_InitTexObj (&textures[totaltex].texObj, textures[totaltex].texture_data, imgProp.imgWidth, imgProp.imgHeight, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
	PNGU_DecodeTo4x4RGBA8 (imgProp.imgWidth, imgProp.imgHeight, textures[totaltex].texture_data, 0xFF);
	DCFlushRange (textures[totaltex].texture_data, imgProp.imgWidth * imgProp.imgHeight * 4);

	// We are done with PNGU
	PNGU_Release ();
	totaltex++;
	return totaltex-1;
};

